package oop.ex1.filters;

import java.io.File;
import java.util.Calendar;
import java.util.Date;
/**
 * an object that check if the file is after a given date
 * @author danalmog
 * @author danielshalev
 */
public class After extends DateDependent {
	/**
	 * construct a new after filter
	 * @param date the date to compare to
	 * @param hasNot indicates if 
	 * @throws FilterDateExeption
	 */
	public After(String date,boolean hasNot) throws FilterDateExeption {
		super(date,hasNot);
	}
	
	/**
	 *  if the file is after a given date
	 *  @return true if the file is after the given date and false otherwise
	 */
	public boolean accept(File pathname){
		Calendar pathDate = Calendar.getInstance();
		Calendar compareDate = Calendar.getInstance();
		pathDate.setTime(new Date(pathname.lastModified()));
		compareDate.setTime(getDate());
		
		//sets the hours minutes and seconds to zero
		pathDate.set(Calendar.HOUR_OF_DAY, 0);
		pathDate.set(Calendar.MINUTE, 0);
		pathDate.set(Calendar.SECOND, 0);
		compareDate.set(Calendar.HOUR_OF_DAY, 0);
		compareDate.set(Calendar.MINUTE, 0);
		compareDate.set(Calendar.SECOND, 0);
		
		//compares the tow dates.
		boolean bigger=pathDate.compareTo(compareDate)>=0;
		if (hasNot)
			return !bigger;
		return bigger;
	} 

}
